-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bounty.go handlers GetAllBounties, GetBountyById, & GetBountyIndexById #1526 #1538
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…onCreatedBounties, GetPersonAssignedBounties, & GetBountyByCreated stakwork#1509
… GetPersonCreatedBounties, GetPersonAssignedBounties, & GetBountyByCreated stakwork#1509" This reverts commit 3b633fe.
@gouravmpk all your tests have failed. Have you tried running the tests locally first? |
Yes I have provided Snapshot in |
That looks like it's for a separate PR. Did you test locally for this specific pr? |
gouravmpk
changed the title
Tests#1526
bounty.go handlers GetAllBounties, GetBountyById, & GetBountyIndexById #1526
Feb 21, 2024
elraphty
reviewed
Feb 21, 2024
elraphty
reviewed
Feb 26, 2024
@gouravmpk you removed the test for getting all bounties rename this to GetPersonAssigned Bounties, and create a test for GetAllBounties, thanks. func TestGetAllBounties(t *testing.T) {
ctx := context.Background()
mockDb := dbMocks.NewDatabase(t)
mockHttpClient := mocks.NewHttpClient(t)
bHandler := NewBountyHandler(mockHttpClient, mockDb)
t.Run("should return bounties assigned to the user", func(t *testing.T) {
mockGenerateBountyResponse := func(bounties []db.Bounty) []db.BountyResponse {
var bountyResponses []db.BountyResponse
for _, bounty := range bounties {
owner := db.Person{
ID: 1,
}
assignee := db.Person{
ID: 1,
}
organization := db.OrganizationShort{
Uuid: "uuid",
}
bountyResponse := db.BountyResponse{
Bounty: bounty,
Assignee: assignee,
Owner: owner,
Organization: organization,
}
bountyResponses = append(bountyResponses, bountyResponse)
}
return bountyResponses
}
bHandler.generateBountyResponse = mockGenerateBountyResponse
expectedBounties := []db.Bounty{
{ID: 1, Assignee: "user1"},
{ID: 2, Assignee: "user1"},
}
mockDb.On("GetAssignedBounties", mock.Anything).Return(expectedBounties, nil).Once()
mockDb.On("GetPersonByPubkey", mock.Anything).Return(db.Person{}, nil)
mockDb.On("GetOrganizationByUuid", mock.Anything).Return(db.Organization{}, nil)
rr := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/wanteds/assigned/uuid", nil)
req = req.WithContext(ctx)
if err != nil {
t.Fatal(err)
}
bHandler.GetPersonAssignedBounties(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
var responseData []db.BountyResponse
err = json.Unmarshal(rr.Body.Bytes(), &responseData)
if err != nil {
t.Fatalf("Error decoding JSON response: %s", err)
}
assert.NotEmpty(t, responseData)
assert.Len(t, responseData, 2)
for i, expectedBounty := range expectedBounties {
assert.Equal(t, expectedBounty.ID, responseData[i].Bounty.ID)
assert.Equal(t, expectedBounty.Assignee, responseData[i].Bounty.Assignee)
}
})
t.Run("should not return bounties assigned to other users", func(t *testing.T) {
mockGenerateBountyResponse := func(bounties []db.Bounty) []db.BountyResponse {
return []db.BountyResponse{}
}
bHandler.generateBountyResponse = mockGenerateBountyResponse
mockDb.On("GetAssignedBounties", mock.Anything).Return([]db.Bounty{}, nil).Once()
rr := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/wanteds/assigned/uuid", nil)
req = req.WithContext(ctx)
if err != nil {
t.Fatal(err)
}
bHandler.GetPersonAssignedBounties(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
var responseData []db.BountyResponse
err = json.Unmarshal(rr.Body.Bytes(), &responseData)
if err != nil {
t.Fatalf("Error decoding JSON response: %s", err)
}
assert.Empty(t, responseData)
assert.Len(t, responseData, 0)
})
} |
elraphty
reviewed
Feb 26, 2024
elraphty
reviewed
Feb 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your changes
Issue ticket number and link
Backend [Integration Test] bounty.go handlers GetAllBounties, GetBountyById, & GetBountyIndexById #1526
Type of change
Test
Checklist before requesting a review